home *** CD-ROM | disk | FTP | other *** search
- Path: tezcat.com!news
- From: Max Rubinstein <maxrubin@tezcat.com>
- Newsgroups: comp.lang.c++
- Subject: Re: MSVC++ Header files/Linker error help needed
- Date: Sun, 17 Mar 1996 00:12:12 -0600
- Organization: Tezcat Communications - Chicago
- Message-ID: <314BAD3C.3C01@tezcat.com>
- References: <4id68p$qa5@news.csus.edu>
- NNTP-Posting-Host: maxrubin.tezcat.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Mike wrote:
- >
- > Please help! I am a very frustrated begenning C++ programmer trying to use
- > MSVC++ 4.0. I am trying to follow good programming practice by declaring my
- > objects and functions in a header file, but I'm having serious trouble. The
- > stuff I'm doing is very simple and shown below:
- >
- > **** header file CTest.h****
- > class CTest
- > {
- > private:
- > int I;
- > public:
- > CTest();
- > CTest(int ToI);
- > void SetI(int ToI);
- > int GetI();
- > };
- >
- > **** Implementation file CTest.cpp ****
- > #include "CTest.h"
- >
- > CTest::CTest(){};
- > CTest::CTest(int ToI)
- > {
- > I = ToI;
- > };
- >
- > void CTest::SetI(int ToI)
- > {
- > I = ToI;
- > };
- >
- > int CTest::GetI()
- > {
- > return I;
- > };
- >
- > **** main file Main.cpp ****
- > #include "CTest.h"
- > #include <iostream.h>
- >
- > void main()
- > {
- > CTest TestObj;
- > TestObj.SetI(9);
- > cout << TestObj.GetI();
- > };
- >
- > This is very basic stuff, or so I thought. If I add the Main.cpp and the
- > CTest.cpp to the console mode project and build it, MSVC++ runs fine, and I
- > get no errors.
- > However, when I create a Windows program (MDI, SDI, Dialog-based) and add the
- > CTest.cpp to the project and the CTest.h to a simple dialog class that I
- > create, upon building the project I receive the following message:
- >
- > :\Projects\test\CTest.cpp(23) : fatal error C1010: unexpected end of file
- > while looking for precompiled header directive
- >
- > If I DO NOT add the CTest.cpp to the project, I receive the following errors:
- >
- > MyDlg.obj : error LNK2001: unresolved external symbol "public: void __thiscall
- > CTest::SetI(int)"(?SetI@CTest@@QAEXH@Z)
- > MyDlg.obj : error LNK2001: unresolved external symbol "public: __thiscall
- > CTest::CTest(void)"(??0CTest@@QAE@XZ)
- >
- > From what I can tell, the compiler cannot or will not find the
- > #include "CTest.h" directive when I have included the cpp file. I have
- > placed the two CTest files (CTest.h and CTest.cpp) in the project directory,
- > added the project directory to the list of directories (under Options) and yet
- > it STILL won't find the header file.
- > I have tried to follow the examples of other files which are included in the
- > project, such as the dialog.h and dialog.cpp (which have no problems
- > building), and yet I continue to get the same error
- > .
- > Can someone please tell me what I'm doing wrong?!!!
- >
- > Before abandoning my investment and switching to Delphi 2.0, I'd like to at
- > least try to figure out what my mistake is, if any. Again, I am relatively
- > new to programming in C++ so I may be missing something really basic here.
- > Readers should note that I am using the default factory settings that MSVC++
- > uses in things like the options, environment, etc. The ONLY change I've made
- > is to smart indent my right block bracket so it lines up with the code, but I
- > doubt that is the cause of my problem. Further, I have downloaded and
- > installed the latest patches.
- >
- > Your help is appreciated.
- >
- > Sincerely,
- > Mike Billard
- > billardm@csus.edu
-
- Mike, there are two possibilities for this behavior:
-
- 1) simply add an empty line at the end of your ctest.h.
-
- If this doesn't help,
- 2) Try to get rid of precompiled headers (in Project Setting, C++
- Tab)and rebuild the project
-
- I am pretty shure that adding another CR at the end of the header will
- help.
-
- Max.
-